﻿using huqiang.Communication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class NetServer
{
    static NetServer _ins;
    public static NetServer Instance { get { if (_ins == null) _ins = new NetServer();return _ins; } }
    KcpServer kcpServer;
    public void OpenServer(int port = 0)
    {
        if (kcpServer == null)
        {
            kcpServer = new KcpServer();
            kcpServer.CreateNew = () => new NetUser();
            kcpServer.AllowFileTransfer = true;
            kcpServer.Run(port, 512);
            kcpServer.OpenHeart();
        }
    }
    public void Dispose()
    {
        kcpServer.CloseHeart();
        kcpServer.Dispose();
    }
    public KcpUser FindLink(int ip, int port)
    {
        return kcpServer.FindLink(ip,port) as KcpUser;
    }
    public KcpUser FindLink(long id)
    {
        return kcpServer.FindLink(id) as KcpUser;
    }
}